package com.cetcs.kmga.dataManager.controller;

import com.cetcs.kmga.common.BaseController;
import com.cetcs.kmga.common.BaseResponse;
import com.cetcs.kmga.common.Constant;
import com.cetcs.kmga.dataManager.annotation.LogAnnotation;
import com.cetcs.kmga.dataManager.entity.global.LogLevelEnum;
import com.cetcs.kmga.dataManager.entity.global.LogTypeEnum;
import com.cetcs.kmga.dataManager.service.dataManager.FTPFlowStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Ftp流量统计
 *
 * @author xutao
 * @version V1.0 创建时间：2017-11-09 11:05
 *          Copyright 2017 by CETC
 */
@RestController
@RequestMapping("/ftpFlowStatistic")
public class FTPFlowStatisticController extends BaseController {

    @Autowired
    private FTPFlowStatisticService ftpFlowStatisticService;

    /**
     * 最近三十天的FTP流量详情
     *
     * @param ftpId    采集数据源的ID
     * @param startDay 起始时间
     * @param endDay   结束时间
     * @return
     */
    @LogAnnotation(module = "数据监管-流量分析-FTP流量", logType = LogTypeEnum.业务日志, description = "最近三十天的FTP流量详情", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findFTPDayFlowList", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findFTPDayFlowList(@RequestParam(value = "id", required = false) String ftpId,
                                           @RequestParam(value = "startDay", required = false) String startDay,
                                           @RequestParam(value = "endDay", required = false) String endDay) {
        try {
            if (StringUtils.isEmpty(ftpId)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "FTP的集群ID不能为空！");
            }
            return this.ok(ftpFlowStatisticService.findFTPDayFlowList(ftpId, startDay, endDay));
        } catch (Exception e) {
            e.printStackTrace( );
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 最近24小时的FTP流量详情
     *
     * @param ftpId   采集数据源ID
     * @param timeDay 某天日期
     * @return
     */
    @LogAnnotation(module = "数据监管-流量分析-FTP流量", logType = LogTypeEnum.业务日志, description = "最近24小时的FTP流量详情", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findFTPHourFlowList", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findFTPHourFlowList(@RequestParam(value = "id", required = false) String ftpId,
                                            @RequestParam(value = "timeDay", required = false) String timeDay) {
        try {
            if (StringUtils.isEmpty(ftpId)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "FTP的集群ID不能为空！");
            }
            return this.ok(ftpFlowStatisticService.findFTPHourFlowList(ftpId, timeDay));
        } catch (Exception e) {
            e.printStackTrace( );
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 每天某个FTP采集点的流量流入流出详情
     *
     * @param ftpId   采集数据源ID
     * @param name    采集数据源名称
     * @param timeDay 统计日期
     * @return
     */
    @LogAnnotation(module = "数据监管-流量分析-FTP流量", logType = LogTypeEnum.业务日志, description = "每天某个FTP采集点的流量流入流出详情", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findDayFlowTotalNum", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findDayFlowTotalNum(@RequestParam(value = "id", required = false) String ftpId,
                                            @RequestParam(value = "name", required = false) String name,
                                            @RequestParam(value = "timeDay", required = false) String timeDay) {
        try {
            if (StringUtils.isEmpty(ftpId)) {
                return this.error(Constant.SYSTEM_EXCEPTION, "FTP的集群ID不能为空！");
            }
            return this.ok(ftpFlowStatisticService.findDayFlowTotalNum(ftpId, name, timeDay));
        } catch (Exception e) {
            e.printStackTrace( );
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 查询所有FTP集群
     *
     * @return
     */
    @LogAnnotation(module = "数据监管-流量分析-FTP流量", logType = LogTypeEnum.业务日志, description = "查询所有FTP集群", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findAllFtpClients", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findAllFtpClients() {
        try {

            return this.ok(ftpFlowStatisticService.findAllFtpClients( ));
        } catch (Exception e) {
            e.printStackTrace( );
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 24小时流量柱状图
     *
     * @return
     */
    @LogAnnotation(module = "数据监管-流量分析-FTP流量", logType = LogTypeEnum.业务日志, description = "24小时流量柱状图", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findFtpHourBarGraph", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findFtpHourBarGraph(@RequestParam(value = "id", required = false) String ftpId,
                                            @RequestParam(value = "timeDay", required = false) String timeDay) {
        try {

            return this.ok(ftpFlowStatisticService.findFtpHourBarGraph(ftpId, timeDay));
        } catch (Exception e) {
            e.printStackTrace( );
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

    /**
     * 近三十天流量柱状图
     *
     * @return
     */
    @LogAnnotation(module = "数据监管-流量分析-FTP流量", logType = LogTypeEnum.业务日志, description = "近三十天流量柱状图", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/findFtpDayBarGraph", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse findFtpDayBarGraph(@RequestParam(value = "id", required = false) String ftpId,
                                           @RequestParam(value = "startDay", required = false) String startDay,
                                           @RequestParam(value = "endDay", required = false) String endDay) {
        try {

            return this.ok(ftpFlowStatisticService.findFtpDayBarGraph(ftpId, startDay, endDay));
        } catch (Exception e) {
            e.printStackTrace( );
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }


    /**
     * 流向SVG统计分析表
     *
     * @return
     */
    @LogAnnotation(module = "数据监管-流向分析", logType = LogTypeEnum.业务日志, description = "流向SVG统计分析表", logLevel = LogLevelEnum.低)
    @RequestMapping(value = "/statFlowSvgGraph", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    public BaseResponse statFlowSvgGraph(HttpServletRequest request) {
        try {

            return this.ok(ftpFlowStatisticService.statFlowSvgGraph(request));
        } catch (Exception e) {
            e.printStackTrace( );
            return this.error(Constant.SYSTEM_EXCEPTION);
        }
    }

}
